$(function () {
    echarts_ajyj();//案件预警
    function echarts_ajyj() {
        // 基于准备好的dom，初始化echarts实例
        let myChart = echarts.init(document.getElementById('echarts_ajyj'));
        CoreUtil.sendPost("/attention/ajyj/chartData", null, function (res) {
            let XY30SL = res.data.xy30sl;
            let DY30TO60SL = res.data.dy30to60sl;
            let DY60TO90SL = res.data.dy60to90sl;
            let DY90SL = res.data.dy90sl;
            myChart.setOption({
                tooltip: {},
                angleAxis: {},
                radiusAxis: {
                    type: 'category',
                    data: ['稽查局', '稽查一局', '稽查二局', '稽查三局'],
                    z: 10
                },
                polar: {},
                series: [
                    {
                        type: 'bar',
                        data:XY30SL,
                        coordinateSystem: 'polar',
                        name: '<=30天',
                        stack: 'a',
                        emphasis: {
                            focus: 'series'
                        }
                    },
                    {
                        type: 'bar',
                        data: DY30TO60SL,
                        coordinateSystem: 'polar',
                        name: '30(不含)-60天',
                        stack: 'a',
                        emphasis: {
                            focus: 'series'
                        }
                    }
                    ,
                    {
                        type: 'bar',
                        data: DY60TO90SL,
                        coordinateSystem: 'polar',
                        name: '60(不含)-90天',
                        stack: 'a',
                        emphasis: {
                            focus: 'series'
                        }
                    }
                    ,
                    {
                        type: 'bar',
                        data: DY90SL,
                        coordinateSystem: 'polar',
                        name: '>90天',
                        stack: 'a',
                        emphasis: {
                            focus: 'series'
                        }
                    }
                ],
                legend: {
                    show: true,
                    data: ['<=30天', '30(不含)-60天','60(不含)-90天','>90天']
                }
            });
        });
        window.addEventListener("resize", function () {
            myChart.resize();
        });
        // 监听点击事件
        myChart.on('click', function(params) {
            // params 中包含了点击事件的相关信息，比如点击的系列名、数据索引等
            console.log(params);
            // 执行你想要的操作，比如弹出提示框、跳转页面等
            let seriesName = params.seriesName;
            let  name = params.name;
        let swjgDm = "";
        if("稽查局" == name ){
            swjgDm="12101009000";
        }else if ("稽查一局"== name){
            swjgDm="12101009100";
        }else if ("稽查二局"== name){
            swjgDm="12101009200";
        }else if ("稽查三局"==name){
            swjgDm="12101009300";
        }
        let dayType = "";
        let title='';
            if("<=30天" == seriesName ){
                dayType="XY30SL";
                title='案件预警明细(' + '<=30天' + ')';
            }else if ("30(不含)-60天"== seriesName){
                dayType="DY30TO60SL";
                title='案件预警明细(' + '30(不含)-60天' + ')';
            }else if ("60(不含)-90天"== seriesName){
                dayType="DY60TO90SL";
                title='案件预警明细(' + '60(不含)-90天' + ')';
            }else if (">90天"==seriesName){
                dayType="DY90SL";
                title='案件预警明细(' + '>90天' + ')';
            }
            let whereParams = {
                "username":"0CF9F5103FA0429B8C0224AF56A1D63B",
                "password":"0CF9F5103FA0429B8C0224AF56A1D63B",
                "serviceId":"0002",
                "param": {
                    "cqyjDetailParams":{
                        "swjgDm":swjgDm,
                        "dayType":dayType,
                        "datasource":"chart"
                    }
                }
            };
            let myParesDataFunction=function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
                }
            };

            table.render({
                elem: '#cqyj_table',
                id: 'cqyj_table',
                contentType: 'application/json',
                headers: {
                    "authorization": token
                },
                cols: [
                    [
                        // {type: 'checkbox', fixed: 'left'},
                        {field: 'jcajbh', title: '案件编号' },
                        {field: 'nsrmc', title: '纳税人名称'},
                        {field: 'nsrsbh', title: '纳税人识别号'},
                        {field: 'larq', title: '立案日期' },
                        {field: 'jcbmmc', title: '所在科室' },
                        {field: 'ajztmc', title: '案件状态'},
                        {field: 'jcry', title: '检查人员'},
                        {field: 'slry', title: '审理人员' },
                    ]
                ],
                page: true ,// 开启分页
                toolbar: '#toolbar',
                where:whereParams,
                url: '/attention/ajyj/detailData', //数据接口
                method: 'POST',
                parseData: myParesDataFunction, done: function(res, curr, count){
                    // 渲染完成后的回调函数
                    let data = res.data; // 获取表格渲染的数据
                    // 遍历表格数据，根据相应字段设置不同颜色
                    for (let i = 0; i < data.length; i++) {
                        let overdueDays = data[i].bh; // 获取超期天数字段
                        let tr = $('#cqyj_table').next().find('tbody tr:eq(' + i + ')'); // 获取当前行对应的 tr 元素

                        if (overdueDays == 1) {
                            tr.css('background-color', '#91CC75');
                        } else if (overdueDays == 2) {
                            tr.css('background-color', '#91CC75');
                        } else if (overdueDays == 3) {
                            tr.css('background-color', '#91CC75');
                        }else if (overdueDays == 4) {
                            tr.css('background-color', 'orange');
                        }else if (overdueDays == 5) {
                            tr.css('background-color', 'orange');
                        }else if (overdueDays == 6) {
                            tr.css('background-color', 'orange');
                        }else if (overdueDays == 7) {
                            tr.css('background-color', '#f33636');
                        }else if (overdueDays == 8) {
                            tr.css('background-color', '#ADD8E6');
                        }
                    }
                }
            });
                layer.open({
                    type : 1,
                    skin : 'layui-layer-molv',
                    title : title,
                    area : [ '100%', '100%' ],
                    shade : 0.8,
                    shadeClose : true,
                    content : jQuery("#cqyj_table_div"),
                    btn : [ '取消' ],
                });
        });
    }
})

















